package sanphone.com.runningschool.MyOrder;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import java.util.List;

import sanphone.com.runningschool.R;
import sanphone.com.runningschool.entity.Order;

public class SendListViewAdapter extends BaseAdapter{
    private List<Order> orders;
    private Context mContext;
    public SendListViewAdapter(Context context, List<Order> infos) {
        mContext = context;
        orders = infos;
    }


    @Override
    public int getCount() {
        return orders.size();
    }

    @Override
    public Object getItem(int position) {
        return orders.get(orders.size()-position);
    }

    @Override
    public long getItemId(int position) {
        return orders.size()-position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
       ViewHolder holder;
        final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (view == null) {
            holder = new ViewHolder();
            view = inflater.inflate(R.layout.send_order_item, null);
           holder.ContentText=view.findViewById(R.id.sendorder_content);
           holder.MonthText=view.findViewById(R.id.s_month);
           holder.DayText=view.findViewById(R.id.s_day);
           holder.DetailText=view.findViewById(R.id.sendorder_detail);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        //控件和数据之间进行绑定
        final Order o= orders.get(position);

        holder.ContentText.setText(
                "物品名称："+o.getThingName()+"\n"+"物品重量："+o.getThingWeight()
                +"\n起始时间："+o.getThingTime()
                +"\n送达时间："+o.getDeliverTime()+"\n起始地址："+o.getThingPlace()+
                "\n送达地址："+o.getDeliverPlace()+"\n酬劳："+o.getMoney()
              );
        holder.MonthText.setText(o.getCreatedTime().substring(5,7)+"月");
        holder.DayText.setText(o.getCreatedTime().substring(8,10));
        holder.ContentText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new Intent(mContext,SendOrderActivity.class);
                intent.putExtra("nickName",o.getNickName());
                intent.putExtra("thingName" ,o.getThingName());
                intent.putExtra("thingPlace",o.getThingPlace());
                intent.putExtra("deliverPlace",o.getDeliverPlace());
                intent.putExtra("thingTime",o.getThingTime());
                intent.putExtra("deliverTime",o.getDeliverTime());
                intent.putExtra("money",o.getMoney());
                intent.putExtra("detail",o.getOtherDeatil());
                intent.putExtra("thingWeight",o.getThingWeight());
                intent.putExtra("behaviorId",o.getBehaviorId());
                intent.putExtra("status",o.getStatus());
                intent.putExtra("acceptName",o.getAcceptName());
                intent.putExtra("acceptPhone",o.getAcceptPhone());
                mContext.startActivity(intent);
            }
        });
        holder.DetailText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(mContext,SendOrderActivity.class);
                intent.putExtra("nickName",o.getNickName());
                intent.putExtra("thingName" ,o.getThingName());
                intent.putExtra("thingPlace",o.getThingPlace());
                intent.putExtra("deliverPlace",o.getDeliverPlace());
                intent.putExtra("thingTime",o.getThingTime());
                intent.putExtra("deliverTime",o.getDeliverTime());
                intent.putExtra("money",o.getMoney());
                intent.putExtra("detail",o.getOtherDeatil());
                intent.putExtra("thingWeight",o.getThingWeight());
                intent.putExtra("behaviorId",o.getBehaviorId());
                intent.putExtra("status",o.getStatus());
                intent.putExtra("acceptName",o.getAcceptName());
                intent.putExtra("acceptPhone",o.getAcceptPhone());
                mContext.startActivity(intent);
            }
        });
        return view;
    }

    class ViewHolder {
      TextView MonthText,DayText,ContentText,DetailText;

    }
}
